package lab03.test13;

import java.sql.*;

public class Test13 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection connection = null;
        Statement statement = null;

        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC", "root", "193749");
            statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT * FROM t_students");
            System.out.println("id" + " stu_no" + " real_name" + " age" + " gender");
            while (resultSet.next() == true) {
                System.out.print(resultSet.getString(1) + "   ");
                System.out.print(resultSet.getString(2) + "   ");
                System.out.print(resultSet.getString(3) + "   ");
                System.out.print(resultSet.getString(4) + "   ");
                System.out.print(resultSet.getString(5) + "   ");
                System.out.println(resultSet.getString(6));
            }

            statement.executeUpdate("DELETE FROM t_students WHERE id = 5");
            statement.executeUpdate("UPDATE t_students set department = '信息与工程学院' WHERE id = 3");
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}

